package cn.cpy.sms.login.handler;

import cn.cpy.sms.login.common.enumerator.ServiceCode;
import cn.cpy.sms.login.common.web.JsonResult;
import cn.cpy.sms.login.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public JsonResult handleServiceException(ServiceException e){
        return JsonResult.fail(e);
    }

    @ExceptionHandler
    public JsonResult handleThrowable(Throwable t){
        String message = "服务器忙，请稍后!";
        log.error(message,t);
        return JsonResult.fail(ServiceCode.ERROR_UNKNOWN,message);
    }
    /*@ExceptionHandler
    public JsonResult handleBindException(BindException e){
        String message = "请求参数格式错误!";
        log.error(message,e);
        return JsonResult.fail(ServiceCode.ERROR_BAD_REQUEST,e.getFieldError().getDefaultMessage());
    }*/
    /*@ExceptionHandler
    public JsonResult handleConstraintViolationException(ConstraintViolationException e){
        String message = "请求参数格式错误!";
        log.error(message,e);
        return JsonResult.fail(ServiceCode.ERROR_BAD_REQUEST,e.getMessage());
    }*/
    /*@ExceptionHandler
    public JsonResult handleAccessDeniedException(AccessDeniedException e){
        String message = "您当前登录的账号无此操作权限!";
        return JsonResult.fail(ServiceCode.ERROR_BAD_REQUEST,message);
    }*/
}
